package com.cwh.controller;

import java.util.List;

import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.cwh.entity.ActiveUser;
import com.cwh.entity.Baoxiaobill;
import com.cwh.service.BaoxiaobillService;

@Controller
public class BaoxiaobillController {
	
	@Autowired
	private BaoxiaobillService baoxiaobillService;
	
	//我的报销单  myBaoxiaoBill
	@RequestMapping("/myBaoxiaoBill")
	public ModelAndView myBaoxiaoBill() {
		//先获取用户实体->存储用户账号 的指定封装类
		ActiveUser activeUser = (ActiveUser)SecurityUtils.getSubject().getPrincipal();
		long id = activeUser.getUserid();
		System.out.println(id);
		//根据userId获取myBaoxiaoBill表对应的报销记录
		List<Baoxiaobill> baoxiaoList = baoxiaobillService.findBaoxiaobillListByUserId(id);
		ModelAndView mv = new ModelAndView();
		mv.addObject("baoxiaoList", baoxiaoList);
		mv.setViewName("baoxiaobill");
		return mv;
	}
	
	//根据报销表id删除报销表记录
	@RequestMapping("deleteBaoxiaobillById")
	public String leaveBillActionDelete(Integer id) {
		baoxiaobillService.deleteBaoxiaobillById(id);
		//重定向路径 myBaoxiaoBill
		return "redirect:/myBaoxiaoBill";
	}

}
